package msg.model;

import java.util.HashMap;
import java.util.Map;
import msg.udp.UDPSocket;


public class MediatorImpl implements Mediator {

	private UDPSocket udpSocket = new UDPSocket();
	private Map<String, ClientData> allClients = new HashMap<String, ClientData>();


	public void send(String id, String msg) {
		ClientData clientData = allClients.get(id);

		this.udpSocket.addSendSocket(clientData.getIp(), clientData.getPort());
		this.udpSocket.send(msg);
	}


	public void register(AppServer serv) {
		this.allClients.put(serv.getUserName(), new ClientData(serv.getUserIp(), serv.getUserPort()));
	}


	public void unRegister(AppServer serv) {
		this.allClients.remove(serv.getUserName());
	}


	public void register(AppClient client) {
		this.allClients.put(client.getServIp(), new ClientData(client.getServIp(), client.getServPort()));
	}
}
